<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <style>
        .layui-card {
            border: 1px solid #f2f2f2;
            border-radius: 5px;
        }

        .layuimini-qiuck-module a i {
            display: inline-block;
            width: 100%;
            height: 60px;
            line-height: 60px;
            text-align: center;
            border-radius: 2px;
            font-size: 30px;
            background-color: #F8F8F8;
            color: #333;
            transition: all .3s;
            -webkit-transition: all .3s;
        }

        .layuimini-qiuck-module a cite {
            position: relative;
            top: 2px;
            display: block;
            color: #666;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            font-size: 14px;
        }

        .welcome-module {
            width: 100%;
        }

        .panel {
            background-color: #fff;
            border: 1px solid transparent;
            border-radius: 3px;
            -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
            box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
            text-align: center;
        }

        .panel-body {
            padding: 10px
        }

        .panel-title {
            margin-top: 0;
            margin-bottom: 0;
            font-size: 12px;
            color: inherit
        }

        .main_btn > p {
            height: 40px;
        }

        .layui-bg-number {
            background-color: #F8F8F8;
        }

        .no-margins {
            color: #00a2d4;
        }

    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!--<fieldset class="table-search-fieldset">-->
            <div class="layui-row layui-col-space10">
                <form class="layui-form layui-form-pane" action="" >
                    <div style="margin: 10px 10px 10px 10px;">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <select name="" id="" lay-filter="status">
                                    <option value="">全部</option>
                                    <option value="1">已出售</option>
                                    <option value="2">出售中</option>
                                    <option value="3">交易中</option>
                                </select>
                            </div>
                            <div class="layui-inline" style="display: none">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>

                    </div>
                </form>
            </div>
        <!--</fieldset>-->
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            {{#  if(d.settlement_status === 1 && d.status == -1){ }}
            <a class="layui-btn layui-btn-xs" lay-event="settlement">结算</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            {{#  } }}
            {{#  if(d.status == 7){ }}
            <a class="layui-btn layui-btn-xs" lay-event="confirmtrade">确认交易</a>
            {{#  } }}
            {{#  if(d.settlement_status === 1 && d.status == 3){ }}
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="detail">修改</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            {{#  } }}
        </script>
    </div>
</div>
{include file="public/footer" /}
<script type="text/html" id="statusTpl">
    {{#  if(d.settlement_status === 2){ }}
    <span>已完成</span>
    {{#  } else if((d.status === -1) &&d.settlement_status === 1) { }}
        <span>已出售</span>
    {{#  } else if((d.status==7) && d.settlement_status === 1) { }}
        <span>待确认</span>
    {{#  } else if((d.status==8) && d.settlement_status === 1) { }}
        <span>等待买家付款</span>
        {{# }else{ }}
        <span>出售中</span>
    {{#  } }}
</script>
<script>
    var form;
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            table = layui.table;
            form = layui.form;
        /*用户卡券*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/TransactionData/lanunch_detail?action=ajax&code='+"{$code}",
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'name', title: '玩家名称', sort: false, align: 'center'},
                {field: 'phone', title: '手机号', sort: false, align: 'center'},
                {field: 'industry_title', title: '行业名称', sort: false, align: 'center'},
                {field: 'team_title', title: '团队名称', sort: true, align: 'center'},
                {field: 'sale_price', title: '投放金额', sort: true, align: 'center'},
                {field: 'growth_cycle', title: '收益周期', sort: true, align: 'center'},
                {field: 'earnings_ratio', title: '收益比例', sort: true, align: 'center'},
                {field: 'precedence_title', title: '优先等级', sort: true, align: 'center'},
                {field: 'plurs_grid', title: '匹配要求', sort: true, align: 'center'},
                {title: '状态', sort: true, align: 'center', templet: '#statusTpl'},
                {title: '操作', toolbar: '#currentTableBar', align: 'center'}
            ]],
            limits: [10,20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        });
        // 监听搜索操作
        form.on('select(status)', function(data){
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    status:data.value
                }
            }, 'data');
            return false;
        });
        /*投放行业*/
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    title: '修改投放行业',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['100%', '100%'],
                    content: '/admin/TransactionData/lanunch_write?id='+data.id,
                    end: function () {
                        location.reload();
                    }
                });
            }else if(obj.event=='delete'){
                layer.confirm('是否立即删除？', function (index) {
                    $.ajax({
                        url:'/admin/TransactionData/deleteBusiness',
                        type:'post',
                        data:{
                            id:data.id,
                        },
                        dataType:'json',
                        async:false,
                        success:function(res){
                            layer.close(index);
                            table.reload('currentTableId', {
                                page: {
                                    curr: 1
                                },
                            }, 'data');
                        }
                    })

                });
            }else if(obj.event=='confirmtrade'){
                layer.confirm('是否确认交易？', function (index) {
                    $.ajax({
                        url:'/admin/TransactionData/confirmtrade',
                        type:'post',
                        data:{
                            id:data.id
                        },
                        dataType:'json',
                        async:false,
                        success:function(res){
                            layer.close(index);
                            table.reload('currentTableId', {
                                page: {
                                    curr: 1
                                },
                            }, 'data');
                        }
                    })

                });
            }else{
                // 结算
                layer.confirm('是否立即结算？', function (index) {
                    $.ajax({
                        url:'/admin/TransactionData/settlementNow',
                        type:'post',
                        data:{
                            id:data.id
                        },
                        dataType:'json',
                        async:false,
                        success:function(res){
                            layer.close(index);
                            table.reload('currentTableId', {
                                page: {
                                    curr: 1
                                },
                            }, 'data');
                        }
                    })

                });
            }
        });

    });
</script>

</body>
</html>